package com.qingzhu.util;

import java.util.Random;

public class RandomString {

    static String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    // 从"str"指定的字符串中获取随机的字符并拼接成字符串，字符串长度由参数length指定
    public static String getRandomString(int length){
        Random random = new Random();
        StringBuffer sb=new StringBuffer();

        for(int i=0;i<length;i++){
            int number = random.nextInt(62);
            sb.append(str.charAt(number));
        }

        return sb.toString();
    }
}
